package com.agent.membership.scheduler;

import com.agent.membership.service.CreditService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 积分定时任务
 * @author Jeff_Wan
 * @description 处理积分的定时任务
 */
@Component
public class CreditScheduler {
    private final CreditService creditService;

    public CreditScheduler(CreditService creditService) {
        this.creditService = creditService;
    }

    /**
     * 每天UTC时间01:00执行积分发放
     */
    @Scheduled(cron = "0 0 1 * * ?", zone = "UTC")
    public void issueDailyCredits() {
        creditService.issueSubscriptionCredits();
    }

    /**
     * 每月1号UTC时间02:00执行积分过期
     */
    @Scheduled(cron = "0 0 2 1 * ?", zone = "UTC")
    public void expireCredits() {
        creditService.expireCredits();
    }
}